package com.cfjjc.gz.usraccount.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.cfjjc.gz.common.action.PagedAction;
import com.cfjjc.gz.common.consts.SystemConst;
import com.cfjjc.gz.common.exception.OTSException;
import com.cfjjc.gz.common.util.StringUtil;
import com.cfjjc.gz.usraccount.service.A_USR_USRGRPService;
import com.cfjjc.gz.usraccount.vo.A_USRVO;
import com.cfjjc.gz.usraccount.vo.A_USR_USRGRPVO;

/**
 * 
 * 说明：对 用户与用户组关系表 进行增删改查的前端处理类
 * 
 
 */
public class A_USR_USRGRPAction extends PagedAction  {

    /**
	 * 
	 */
	private static final long serialVersionUID = -4898782468043703025L;

	private A_USR_USRGRPVO model = new A_USR_USRGRPVO();

    @Autowired
    private A_USR_USRGRPService a_USR_USRGRPService;

    public A_USR_USRGRPAction() {
        super();
		this.setQUERY_NAME("browseA_USR_USRGRPList");
    }

    // 显示用户与用户组关系表管理首页
    public String showIndex() throws Exception {
        return INDEX;
    }

    // 显示用户与用户组关系表列表页面
    public String queryList() throws Exception {
        preparePagedList(QUERY_NAME, getModel());
        if (!pagedRecords.exists()) {
            try {
                a_USR_USRGRPService.queryA_USR_USRGRPs((A_USR_USRGRPVO) pagedRecords.getParam(), pagedRecords);
            } catch (OTSException e) {
                this.addActionError(e.getMessage());
				return ERROR;
            }
        }
        return LIST;
    }

    // 根据某用户组，显示该用户组已选的用户列表页面
    public String showSelectedUsr() throws Exception {
    	return "selected_usr";
    }
    
    // 根据某用户组，查询该用户组已选的用户列表信息
    public String querySelectedUsrList() throws Exception {
    	
    	preparePagedList(QUERY_NAME, getModel());
    	if (!pagedRecords.exists()) {
    		try {
    			a_USR_USRGRPService.querySelectedUsrList((A_USR_USRGRPVO) pagedRecords.getParam(), pagedRecords);
    		} catch (OTSException e) {
    			this.addActionError(e.getMessage());
    			return ERROR;
    		}
    	}
    	return LIST;
    }
    
    // 根据某用户组，显示该用户组未选的用户列表页面
    public String showNotselectedUsr() throws Exception {
    	return "not_selected_usr";
    }
    
    // 根据某用户组，查询该用户组未选的用户列表信息
    public String queryNotselectedUsrList() throws Exception {
    	preparePagedList(QUERY_NAME, getModel());
    	if (!pagedRecords.exists()) {
    		try {
    			a_USR_USRGRPService.queryNotselectedUsrList((A_USR_USRGRPVO) pagedRecords.getParam(), pagedRecords);
    		} catch (OTSException e) {
    			this.addActionError(e.getMessage());
    			return ERROR;
    		}
    	}
    	return LIST;
    }
    
    // 显示用户与用户组关系表的明细页面
	public String showInfo() throws Exception {
		try {
			if (StringUtil.isEmpty(model.getKey())) {
				return INFO;
			}

			A_USR_USRGRPVO param=new A_USR_USRGRPVO();
        	param.setKey(model.getKey());
			model=a_USR_USRGRPService.queryA_USR_USRGRP(param);
		} catch (OTSException e) {
			this.addActionError(e.getMessage());
			return ERROR_PAGE;
		}
		return INFO;
	}

    // 显示用户与用户组关系表录入页面
    public String showAdd() throws Exception {
        setOperationType(SystemConst.OPERATION_TYPE_NEW);
        return INPUT;
    }

    // 保存用户与用户组关系表录入
    public String doInsert() throws Exception {
        try {
        	A_USRVO usr = (A_USRVO) session.get(SystemConst.SESSION_USER);
        	model.setCreate_by(usr.getUsr_id());
        	model.setNode_id(SystemConst.NODE_ID);
            a_USR_USRGRPService.doInsertA_USR_USRGRP(model, id);
        } catch (OTSException e) {
            this.addActionError(e.getMessage()); 
            return ERROR;
        }
        return NONE;
    }

    // 显示修改页面
    public String showEdit() throws Exception {
       try {
       		if (StringUtil.isEmpty(model.getKey())) {
				return INPUT;
			}

        	A_USR_USRGRPVO param=new A_USR_USRGRPVO();
        	param.setKey(model.getKey());
            model=a_USR_USRGRPService.queryA_USR_USRGRP(param);
        } catch (OTSException e) {
            this.addActionError(e.getMessage());
			return ERROR_PAGE;
        }

        setOperationType(SystemConst.OPERATION_TYPE_MODIFY);
        return INPUT;
    }

    // 保存对用户与用户组关系表的修改
    public String doUpdate() throws Exception {
        try {
        	A_USRVO usr = (A_USRVO) session.get(SystemConst.SESSION_USER);
        	model.setUpdate_by(usr.getUsr_id());
            a_USR_USRGRPService.doUpdateA_USR_USRGRP(model);
        } catch (OTSException e) {
            this.addActionError(e.getMessage());
            return ERROR;
        }
        return NONE;
    }

    // 删除用户与用户组关系表。允许批量删除。允许部分删除成功
    public String doDelete() throws Exception {
        try {
            for (int n = 0; n < id.length; n++) {
                A_USR_USRGRPVO param = new A_USR_USRGRPVO();
                param.setKey(id[n]);
                a_USR_USRGRPService.doDeleteA_USR_USRGRP(param);
            }
        } catch (OTSException e) {
            this.addActionError(e.getMessage());
            return ERROR;
        }
        return NONE;
    }    

    /** 以下为set,get方法 */
    public Object getModel() {
        return model;
    }
}
